package com.administrator.customviewtest.view_group;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.administrator.customviewtest.R;

import java.util.Arrays;
import java.util.List;

/**
 * Created by Administrator on 2017/5/18.
 */

public class RecyclerviewTestAct extends Activity {
    private RecyclerView recyclerView;
    private List<String> list;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rv_test);

        recyclerView = (RecyclerView) findViewById(R.id.rv);

        list = Arrays.asList("1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj","1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj","1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj","1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj","1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj","1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj","1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj","1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj","1", "2", "3", "4", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5"
                , "5", "5", "5", "5", "5", "5", "5", "5", "fsdfsdfsdf", "fsdlkjfldsjflkdsjflk", "fsdfhdshfkjsdhfkj");

        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
        recyclerView.setLayoutManager(new MyLayoutManager());
        recyclerView.setAdapter(new Adapter());


    }

    private class Adapter extends RecyclerView.Adapter<ViewHolder> {

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new ViewHolder(View.inflate(parent.getContext(), R.layout.item_test, null));
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            holder.textView.setText(list.get(position));
        }

        @Override
        public int getItemCount() {
            return list.size();
        }
    }

    private class ViewHolder extends RecyclerView.ViewHolder {
        private TextView textView;

        public ViewHolder(View itemView) {
            super(itemView);

            textView = (TextView) itemView.findViewById(R.id.tv);
        }
    }
}
